package handler

import (
	"ecommerce-customer-support-chat/api/request"
	"ecommerce-customer-support-chat/internal/dao"
	"ecommerce-customer-support-chat/internal/model"
	"github.com/gin-gonic/gin"
	"net/http"
)

func CreateService(c *gin.Context) {
	var req request.CreateServiceReq

	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 1000,
			"msg":  "验证失败",
			"data": nil,
		})
		return
	}
	var service model.CustomerService

	if service.Id == 0 {
		service = model.CustomerService{

			ServiceUserId: req.ServiceUserId,
			ServiceName:   req.ServiceName,
			ServiceType:   req.ServiceType,
		}
		if !dao.Create(&service) {
			c.JSON(http.StatusOK, gin.H{
				"code": 1000,
				"msg":  "客服团队创建失败",
				"data": nil,
			})
			return
		}
		c.JSON(http.StatusOK, gin.H{
			"code": 200,
			"msg":  "客服团队创建成功",
			"data": service,
		})

	}
}
